% pearson correlation of 2 ts 			-	15.08.2000
% latest date 12.10.2001
% Ref : Molyneux, J.B. & Schmitt, D.R., 1999, 
% First-break timing : Arrival onset times by 
% direct correlation, Geophysics, 64, 1492 - 1501.
% 
function [R] = corpr(X,Y)
% bug found, not rectified 18.12.2001
% rectified - 10.11.2002

if length(X) ~= length(Y),
   R=-999;
   return;
end;
  
n1 = length(X);
N1 = n1 * sum (X.*Y);
N2 = sum(X) * sum(Y);

D1 = sqrt ( n1*sum(X.^2) - sum(X)^2 );
D2 = sqrt ( n1*sum(Y.^2) - sum(Y)^2 );
R = (N1-N2) / (D1*D2) ;
